package cn.lystudio.rohmtimeopwide_background_v11.controller.appApi;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.util.SaResult;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.lystudio.rohmtimeopwide_background_v11.entity.po.OpItemPO;
import cn.lystudio.rohmtimeopwide_background_v11.service.OpItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/app-api/opitem")
@CrossOrigin
@SaIgnore
@Slf4j
public class AppOpItemController {
    private OpItemService opItemService;
    @Lazy
    @Autowired
    public void setOpItemService(OpItemService opItemService) {
        this.opItemService = opItemService;
    }

    @GetMapping("/getOpItemListByMachineNo")
    public SaResult getOpItemListByMachineNo(@RequestParam("machineNo") String machineNo){
        List<OpItemPO> opItemList = opItemService.getOpItemListByMachineNo(machineNo);
        if(CollUtil.isEmpty(opItemList)) return SaResult.error("该机台下没有操作项");
        return SaResult.data(opItemList);
    }

    @GetMapping("/getOpitemByOpItemNameAndMachineNo")
    public SaResult getOpitemByOpItemNameAndMachineNo(String opItemName,String machineNo){
        OpItemPO opitem = opItemService.getOpitemByOpItemNameAndMachineNo(opItemName, machineNo);
        if(ObjectUtil.isEmpty(opitem)) return SaResult.error("设置值已变更,无法修改数据");
        return SaResult.data(opitem);
    }

}
